package com.daluzy.chmanager.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.daluzy.chmanager.R;
import com.daluzy.chmanager.bean.Manager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ManagerAdapter extends RecyclerView.Adapter<ManagerAdapter.MyViewHolder> {


    private Context context;
    private List<Manager> myData = new ArrayList<>();

    public ManagerAdapter(Context context, List<Manager> myData) {
        this.context = context;
        this.myData = myData;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.manager_item_daluzy, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Manager manager = myData.get(position);
        holder.tvManagerName.setText(manager.getManager_name());
        holder.tvManagerPhone.setText(manager.getManager_phone());
        if (!TextUtils.isEmpty(manager.getSchool_name()))
            holder.tvManagerSchool.setText(manager.getSchool_name());

    }

    @Override
    public int getItemCount() {
        return myData.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_manager_name)
        TextView tvManagerName;
        @BindView(R.id.tv_manager_phone)
        TextView tvManagerPhone;
        @BindView(R.id.tv_manager_school)
        TextView tvManagerSchool;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
